﻿using System;
using System.ComponentModel.DataAnnotations;

using MSAcademic.v2.Infrastructure.AccessRights;
using MSAcademic.v2.Infrastructure.Login;
using MSAcademic.v2.Infrastructure.User;

namespace MSAcademic.v2.Web.Areas.Admin.Models.Section
{
    public partial class NewSubSectionModel
    {
       public int contentId { get; set; }

       [Required(ErrorMessage = "Polje ne smije biti prazno!")]
       public string name { get; set;}

       public string thumbnailUrl { get; set; }
    }

    public partial class NewSubSectionModel
    {
        public IUser SignedInUser
        {
            get
            {
                if (_signedInUser == null)
                {
                    _signedInUser = new Lazy<IUser>(() => _loginService.TryGetSignedInUser());
                }
                return _signedInUser.Value;
            }
        }
        private Lazy<IUser> _signedInUser;

        public bool CanAccess
        {
            get
            {
                if (_canAccess == null)
                {
                    _canAccess = new Lazy<bool>(() => this.SignedInUser != null && _accessRightsService.CanUserAccess(this.SignedInUser, AccessRight.SectionControl));
                }
                return _canAccess.Value;
            }
        }
        private Lazy<bool> _canAccess;
    }

    public partial class NewSubSectionModel
    {
        private readonly ILoginService _loginService;
        private readonly IAccessRightsService _accessRightsService;

        public NewSubSectionModel(
            ILoginService loginService,
            IAccessRightsService accessRightsService)
        {
            _loginService = loginService;
            _accessRightsService = accessRightsService;
        }
    }
}